<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <table border="1" width="500px" height="400px" align="center" style="text-align:center; border-collapse:collapse; color:red; border-color:blue;">
        
    <tr>
        <td colspan="3">1</td>
        
    </tr>
    
    <tr>
        <td rowspan="2">2</td>
        <td colspan="2">3</td>
        
    </tr>
    
    <tr>
        <td>6</td>
        
        <td rowspan="2">7</td>
    </tr>
    
    
    <tr>
      <td rowspan="2">4</td>
      <td>5</td>
    </tr>

    
    <tr>

        <td colspan="2">8</td>
    
    </tr>
</table>
  <script>
    var maximumGap = function (nums) {
      const n = nums.length;
      if (n < 2) {
        return 0;
      }
      let exp = 1;
      const buf = new Array(n).fill(0);
      const maxVal = Math.max(...nums);

      while (maxVal >= exp) {
        
        
        const cnt = new Array(10).fill(0);
        for (let i = 0; i < n; i++) {
          let digit = Math.floor(nums[i] / exp) % 10;
          cnt[digit]++;
        }
        for (let i = 1; i < 10; i++) {
          cnt[i] += cnt[i - 1];
        }
        for (let i = n-1; i >= 0; i--) {
        // for (let i = 0; i < n; i++) {
          let digit = Math.floor(nums[i] / exp) % 10;
          buf[cnt[digit] - 1] = nums[i];
          
          cnt[digit]--;
          
        }
        nums.splice(0, n, ...buf);
        exp *= 10;
      }

      let ret = 0;
      for (let i = 1; i < n; i++) {
        ret = Math.max(ret, nums[i] - nums[i - 1]);
      }
      return ret;
    };
    var arr = [5, 8, 95, 54, 58, 98, 315, 9874, 321, 52, 54, 454, 18]
    maximumGap(arr)
  </script>
</body>
</html>
<!-- [321, 52, 54, 9874, 54, 454, 5, 95, 315, 8, 58, 98, 18][5, 8, 315, 18, 321, 52, 54, 54, 454, 58, 9874, 95, 98] -->
<!-- [321, 52, 454, 54, 9874, 54, 315, 95, 5, 18, 98, 58, 8][8, 5, 18, 315, 321, 58, 54, 54, 454, 52, 9874, 98, 95] -->